/*** 
 * @_______________#########_______________________ 
 * @______________############_____________________ 
 * @______________#############____________________ 
 * @_____________##__###########___________________ 
 * @____________###__######_#####__________________ 
 * @____________###_#######___####_________________ 
 * @___________###__##########_####________________ 
 * @__________####__###########_####_______________ 
 * @________#####___###########__#####_____________ 
 * @_______######___###_########___#####___________ 
 * @_______#####___###___########___######_________ 
 * @______######___###__###########___######_______ 
 * @_____######___####_##############__######______ 
 * @____#######__#####################_#######_____ 
 * @____#######__##############################____ 
 * @___#######__######_#################_#######___ 
 * @___#######__######_######_#########___######___ 
 * @___#######____##__######___######_____######___ 
 * @___#######________######____#####_____#####____ 
 * @____######________#####_____#####_____####_____ 
 * @_____#####________####______#####_____###______ 
 * @______#####______;###________###______#________ 
 * @________##_______####________####______________ 
 * @
 * @Author: ipk518 18163976442@163.com
 * @Date: 2024-12-10 10:18:34
 * @LastEditors: ipk518 121206530@qq.com
 * @LastEditTime: 2025-08-08 14:46:41
 * @FilePath: /etws-sxk2307/inc/Qsfp.h
 * @Description: 
 * @************佛祖保佑************
 * @Copyright (c) 2024 by etws@quyujiang, All Rights Reserved. 
 */

#ifndef _QSFP_H
#define _QSFP_H

#include "stdio.h"
#include "stdint.h"
#include "qsfp_4x.h"
#include "qsfp_12x.h"

#define QSFP_PAGESIZE 128
#define QSFP_PAGEMASK 255
#define QSFP_PAGEUPPER (QSFP_PAGEMASK - QSFP_PAGESIZE + 1)

#define QSFP_PAGE 127
#define QSFP_PAGENUM_4X 3
#define QSFP_PAGENUM_12X 2

#define QSFP_PAGA_4X_0 0x0
#define QSFP_PAGA_4X_2 0x2
#define QSFP_PAGA_4X_3 0x3

#define QSFP_PAGA_12X_0 0x0
#define QSFP_PAGA_12X_1 0x1


#define X4_DEV_NAME "/dev/i2c-1"
#define X12_DEV_NAME "/dev/i2c-9"



struct qsfpUpdate
{
    double m_inRx1Power;                //RX1通道功率,RX input power
    double m_inRx2Power;                //RX2通道功率
    double m_inRx3Power;                //RX3通道功率
    double m_inRx4Power;                //RX4通道功率
    
    double m_inTx1Power;                //TX1通道功率,TX output power
    double m_inTx2Power;                //TX2通道功率,TX output power
    double m_inTx3Power;                //TX3通道功率,TX output power
    double m_inTx4Power;                //TX4通道功率,TX output power


    double m_inTx1Bias;                 //TX1通道偏置电流 内部偏置电流
    double m_inTx2Bias;                 //TX2通道偏置电流 内部偏置电流
    double m_inTx3Bias;                 //TX3通道偏置电流 内部偏置电流
    double m_inTx4Bias;                 //TX4通道偏置电流 内部偏置电流
    
    double m_monitorVcc1;               //电压监控
    int16_t m_monitorTemp1;              //温度监控
};

extern int m_qsfp_4x_fd;
extern int m_qsfp_12x_fd;

extern uint8_t m_qsfp_4x_upper[QSFP_PAGENUM_4X][QSFP_PAGEUPPER];
extern uint8_t m_qsfp_12x_tx_upper[QSFP_PAGENUM_12X][QSFP_PAGEUPPER];
extern uint8_t m_qsfp_12x_rx_upper[QSFP_PAGENUM_12X][QSFP_PAGEUPPER];

extern int qsfp_4x_init();
extern int qsfp_12x_init();

extern int qsfp_4x_check();
extern void qsfpClose();
extern int qsfp_power();

extern int refresh_qsfp_4x_cache(struct qsfp_4x_cache *cp);
extern int refresh_qsfp_12x_tx_cache(struct qsfp_12x_Txcache *cp);
extern int refresh_qsfp_12x_rx_cache(struct qsfp_12x_Rxcache *cp);

// extern uint8_t qsfp_4x_transmit(uint8_t reg, uint8_t *rdata, uint8_t rlen, uint8_t *wdata, uint8_t wlen);
// extern uint8_t qsfp_12x_transmit(uint8_t reg, uint8_t *rdata, uint8_t rlen, uint8_t *wdata, uint8_t wlen);

extern int qsfp_page_4x_change(int page);
extern int qsfp_page_12x_tx_change(int page);
extern int qsfp_page_12x_rx_change(int page);

extern void refresh_qsfp_4x_upperMemory();
extern void refresh_qsfp_12x_tx_upperMemory();
extern void refresh_qsfp_12x_rx_upperMemory();

extern void qsfpGetStatus(struct qsfpUpdate &m_qsfpUpdate) ;

#endif